package com.beimi.room;

import java.util.Date;

public class Room {
	
	private int id;
	
	private Date createTime;
	
	private RoomPlayer[] seats;
	
	public Room()
	{
		seats = new RoomPlayer[4];
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	public boolean addPlayer(RoomPlayer player)
	{
		for (RoomPlayer matchPlayer : seats) {
			if (matchPlayer == player) {
				return false;
			}
		}
		
		int index = findEmptySeat();
		if (index != -1) {
			seats[index] = player;
		}
		
		return true;
	}

	private int findEmptySeat() {
		for (int i = 0; i < seats.length; i++) {
			if (seats[i] == null) {
				return i;
			}
		}
		return 0;
	}
}
